package com.ilink.teacherservice.service.impl.bailian;

import com.aliyun.bailian20231229.models.AddFileResponse;
import com.aliyun.tea.TeaException;
import org.springframework.stereotype.Service;

@Service
public class AddFileService {

    /**
     * 返回格式
     *{
     *   "Status": 200,
     *   "RequestId": "8EC422A4-059F-5923-8A4C-4AE6A1821322",
     *   "Message": "",
     *   "Data": {
     *     "FileId": "file_cbf70c25505c4674a0da271cdc47f335_10249160",
     *     "Parser": "DASHSCOPE_DOCMIND"
     *   },
     *   "Code": "Success",
     *   "Success": true
     * }
     **/
    public AddFileResponse addFile(com.aliyun.bailian20231229.Client client, String leaseId, String parser, String categoryId, String workspaceId) throws Exception {
        com.aliyun.bailian20231229.models.AddFileRequest addFileRequest = new com.aliyun.bailian20231229.models.AddFileRequest()
                .setLeaseId(leaseId)
                .setParser(parser)
                .setCategoryId(categoryId);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        try {
            // 复制代码运行请自行打印 API 的返回值
            return client.addFileWithOptions(workspaceId, addFileRequest, headers, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new TeaException(error.getMessage(), error);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new Exception(error.getMessage());
        }
    }
}
